package com.dkt.android.mvp.ui.act

import android.os.Bundle
import android.widget.Button
import android.widget.EditText
import com.alibaba.android.arouter.facade.annotation.Route
import com.dkt.android.R
import com.dkt.android.base.BaseActivity
import com.dkt.android.core.RouterHub
import com.dkt.android.mvp.contract.LoginContract
import com.dkt.android.mvp.model.LoginInfo
import com.dkt.android.mvp.presenter.LoginPresenter
import com.dkt.android.utils.Utils




@Route(path = RouterHub.APP_LOGIN_ACTIVITY)
class LoginActivity : BaseActivity() , LoginContract.LoginView {

    private var account: EditText? = null
    private var password: EditText? = null

    override fun getLayoutResource(): Int=R.layout.activity_login

    private val presenter : LoginContract.Presenter by lazy {
        val b= LoginPresenter()
        b.register(this,handler)
        return@lazy b
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        initView()
    }

    private fun initView(){
        account = findViewById(R.id.et_account)
        password = findViewById(R.id.et_passWord)
        findViewById<Button>(R.id.loginBtn)?.setOnClickListener {
            Utils.navigation(this@LoginActivity, RouterHub.APP_MAIN_ACTIVITY)
//            login()
        }
        findViewById<Button>(R.id.registerBtn)?.setOnClickListener {
            Utils.navigation(this@LoginActivity, RouterHub.APP_REGISTER_ACTIVITY)
        }
    }

    private fun login(){
        val info = LoginInfo()
        val n = account?.text.toString()
        val p = password?.text.toString()
        info.pwd = p
        info.account = n
        presenter.toLogin(this, info)
    }

    override fun loginSuccess() {
        Utils.navigation(this@LoginActivity, RouterHub.APP_MAIN_ACTIVITY)

    }

    override fun loginError() {

    }

}